package com.yisu.expressway.onedollar.fragment;

import com.yisu.expressway.fragment.BaseFragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;

/**
 * Created by Kaven on 2016/12/19.
 */

public abstract class BasicFragment extends BaseFragment {
    private View mView;
    private int mLayoutId;

    protected BasicFragment() {
        this.mLayoutId = getInflateLayoutId();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        if (null == mView) {
            mView = inflater.inflate(mLayoutId, container, false);
            ButterKnife.bind(this, mView);
            initViews(mView);
            bindEvents();
        } else {
            ViewGroup parent = (ViewGroup) mView.getParent();
            if (parent != null) {
                parent.removeView(mView);
            }
        }

        return mView;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        releasePresenter();
    }

    protected abstract int getInflateLayoutId();

    protected abstract void initPresenter();

    protected abstract void releasePresenter();

    protected abstract void getIntentData(Intent intent);

    protected abstract void getSavedBundleData(Bundle bundle);

    protected abstract void initViews(View view);

    protected abstract void bindEvents();
}
